package com.dmz.insclient.utils;

import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;

import java.io.*;

/**
 * @author lee
 */
@Slf4j
public class FileUtils {

    public static byte[] file2byte(File file) {

        byte[] byffer = null;
        try {
            BufferedInputStream fis = FileUtil.getInputStream(file);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] b = new byte[1024];
            int n;
            while ((n = fis.read(b)) != -1) {
                bos.write(b, 0, n);
            }
            fis.close();
            bos.close();
            byffer = bos.toByteArray();
        } catch (Exception e) {
            log.error("file2byte异常：{}", String.valueOf(e));
        }
        return byffer;
    }


}
